<template>
	<view class="vehicle">
		<u-navbar title="车辆管理" title-color="#333" back-icon-color="#333"></u-navbar>
		<view class="vehicle-bottom">
			<view class="vehicle-car">
				<!-- <view class="vehicle-car-box">
					<text class="vehicle-stick"></text>
					<text class="vehicle-car-details">车辆详情</text>
				</view> -->
				<view class="vehicle-add" @click="addCar">
					<text class="iconfont icontianjia"></text>
					<text class="vehicle-add-button">添加</text>
				</view>
			</view>
			<!-- 内容 -->
			<view class="vehicle-content-box" v-if="vehicleArrList.length!=0" v-for="(item,index) of vehicleArrList" :key="index">
				<!--  -->
				<view class="vehicle-car vehicle-content">
					<!-- 车牌号 -->
					<text class="vehicle-car-details vehicle-carNumber" ref="carNumbers">{{item.SETTB402CA00}}</text>
				</view>
				<!--  -->
				<view class="vehicle-content-bottom">
					<view class="vehicle-carName-phone">
						<view class="vehicle-carName">
							<text class="vehicle-phone">车主姓名:</text>
							<text class="vehicle-input-one">{{item.carname}}</text>
						</view>
						<view class="">
							<text class="vehicle-phone">联系方式:</text>
							<text v-if="typeof(item.phonenumber)=='object'" class="vehicle-input-two">{{item.phonenumber[0].phone}}</text>
							<text v-else class="vehicle-input-two">{{item.phonenumber}}</text>
						</view>
					</view>
					<view class="vehicle-carName-phone">
						<view class="vehicle-carName">
							<text class="vehicle-phone">皮重:</text>
							<text class="vehicle-input-one">{{item.SETTB402CA03}}</text>
						</view>
					</view>
					<!--  -->
					<view class="vehicle-button-box">
						<view class="vehicle-add vehicle-button-margin" @click="modify(item)" style="background: rgba(229, 191, 0, 1);">
							<text class="iconfont iconxiugai"></text>
							<text class="vehicle-add-button" ref='modify'>修改</text>
						</view>
						<view class="vehicle-add" @click="prohibit(item)" style="background: rgba(255, 76, 76, 1);">
							<text class="iconfont iconshanchu"></text>
							<text class="vehicle-add-button">删除</text>
						</view>
					</view>
				</view>
			</view>
			<!--  -->
			<view class="sendorder-loadmore">
				<u-loadmore v-if="vehicleArrList.length!=0" :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
			<!-- 缺醒页 -->
			<view class="zanWSJ" v-if="vehicleArrList.length==0">
				<image :src="getStaticFilePath('/QXY/noData.png')" alt="">
			</view>
			<u-modal v-model="vehicleLoginShow" :content="vehicleContent" :show-cancel-button="true" @confirm="vehicleConfirm"></u-modal>
			<!-- <u-select v-model="carTypeShow" :default-value="carTypeIndex" :list="carTypeList" @confirm="carTypeOnConfirm"> -->
			</u-select>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				status: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				countpage: 1,
				page: 1,
				vehicleArrList: [],
				vehicleLoginShow: false,
				vehicleContent: '',
				carID: '', //车辆ID
				SETTB402ID:'',
				
			}
		},
		onShow() {
			this.vehicleList();
		},
		onReachBottom() {
			if (this.page == this.countpage) {
				return this.status = "nomore"
			}
			this.page++
			this.vehicleList()
		},
		methods: {
			// 删除
			vehicleConfirm() {
				uni.request({
					url: this.baseUrl + '/set/settb402/delete',
					method: 'post',
					dataType: 'json',
					data: {
						SETTB402ID: this.SETTB402ID,
						carID: this.carID,
						sign: this.userinfo.sign,
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '删除成功',
								duration: 5000,
								icon: 'none',
							});
							this.page = 1
							this.countpage = 1
							this.vehicleList();
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			prohibit(item) {
				this.vehicleLoginShow = true
				this.SETTB402ID = item.SETTB402ID
				this.carID=item.carID
				this.vehicleContent = '您确定要删除车辆' + item.SETTB402CA00 + '吗？'
			},
			modify(item) {
				let testStr
				
				if(typeof(item.phonenumber) == 'object'){
					
					testStr = encodeURIComponent(JSON.stringify(item.phonenumber));
				}
				else{
					let phoneArr = [{
						phone:''
					}]
					phoneArr[0].phone = item.phonenumber
					testStr = encodeURIComponent(JSON.stringify(phoneArr));
				}
				
				uni.navigateTo({
					url: '../vehicleModifyCar/index' +
						`?carNumberIpt=${item.SETTB402CA00}&nameIpt=${item.carname}&phoneIpt=${testStr}&tareIpt=${item.SETTB402CA03}&SETTB402ID=${item.SETTB402ID}&carID=${item.carID}`
				})
			},
			//添加
			addCar() {
				uni.navigateTo({
					url: '../vehicleAddCar/index'
				})
			},
			vehicleList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				this.status = "loading"
				if (this.userinfo.sign == 'CUS-1') {
					var ORMTB400ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2'||this.userinfo.sign == 'CUS-3') {
					var ORMTB400ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/set/settb402/selectPageList',
					method: 'POST',
					dataType: 'json',
					data: {
						sign: this.userinfo.sign,
						personID: ORMTB400ID,//一二级客户id
						page: this.page,
						limit: 10,
					},
					success: (res) => {
						uni.hideLoading();
						console.log(res);

						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.vehicleArrList = []
								this.page = 1
								this.countpage = 1
								return
							}
							var data = res.data.data || []
							if (this.page > 1) {
								this.vehicleArrList = [...this.vehicleArrList, ...data]
							} else {
								this.vehicleArrList = data
							}
							this.countpage = Math.ceil(res.data.count / 10)
						} else {
							this.vehicleArrList = []
							this.page = 1
							this.countpage = 1
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
					},
					fail: (res) => {
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
						uni.hideLoading();
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
		}
	}
</script>

<style scoped>
	.sendorder-loadmore {
		padding: 20rpx 0 20rpx 0;
	}

	.vehicle .zanWSJ {
		padding-top: 200rpx;
	}

	.vehicle .zanWSJ>image {
		display: block;
		margin: 0 auto;
		height: 360rpx;
		width: 43%;
	}


	.vehicle {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	.vehicle .vehicle-car {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx;
	}

	.vehicle .vehicle-car-box {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .vehicle-stick {
		width: 6rpx;
		height: 29rpx;
		display: inline-block;
		background: linear-gradient(0deg, rgba(57, 163, 216, 1), rgba(35, 199, 217, 1));
		border-radius: 8px;
		margin-right: 16rpx;
		line-height: 29rpx;
		position: relative;
		top: 2rpx;
	}

	.vehicle .vehicle-car-details {
		font-size: 32rpx;
		color: rgba(51, 51, 51, 1);
		height: 29rpx;
		line-height: 29rpx;
		/* height: 0.37rem;
	  line-height: 0.37rem; */
	}

	/* 添加 */
	.vehicle-add {
		height: 44rpx;
		font-size: 28rpx;
		color: rgba(255, 254, 254, 1);
		background: rgba(0, 160, 241, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .icontianjia,
	.vehicle .iconxiugai,
	.vehicle .iconbaocun,
	.vehicle .iconshanchu,
	.vehicle .iconqiyong {
		font-size: 26rpx;
		padding-left: 10rpx;
	}

	.vehicle-add-button {
		padding: 0 10rpx;
	}

	/* 内容 */
	.vehicle-content-box {
		width: 100%;
		background: rgba(255, 255, 255, 1);
	}

	.vehicle .vehicle-content {
		margin-top: 8rpx;
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
	}

	.vehicle .vehicle-carNumber {
		font-size: 30rpx !important;
		font-weight: bold;
	}

	/* .vehicle .vehicle-bottom view:nth-child(3)>view:first-child text:first-child {} */

	.vehicle .vehicle-button-box {
		display: flex;
		justify-content: flex-end;
		padding: 30rpx 0;
	}

	.vehicle-button-margin {
		margin-right: 20rpx;
	}

	.vehicle-content-bottom {
		padding: 0 24rpx;
	}

	.vehicle-carName-phone {
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
		display: flex;
		justify-content: space-between;
		padding: 18rpx 0;
	}

	.vehicle input {
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 43rpx !important;
		margin-left: 7rpx;
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
		text-align: center;
		border: 2rpx solid rgba(0, 0, 0, .2);
		border-radius: 6rpx;
	}

	.inputBorder {
		border: none !important;
		text-align: left !important;
	}

	.vehicle-input-one {
		width: 166rpx !important;
	}

	.vehicle-input-two {
		width: 190rpx !important;
	}

	.vehicle-phone {
		width: 142rpx;
		display: inline-block;
		font-size: 30rpx;
		color: rgba(153, 153, 153, 1);
	}

	.vehicle-tare {
		padding: 18rpx 0;
	}

	.vehicle-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}
</style>
